import java.util.HashMap;
import java.util.LinkedList;
import java.util.Queue;

/**
 * Created by zhangjinrui on 17/6/27.
 */

public class Solution397 {

    public static void main(String args[]) {
        Solution397 s = new Solution397();
        System.out.println(s.integerReplacement(Integer.MAX_VALUE));
    }

    public int integerReplacement(int n) {
        int step = 0;
        while (n != 1) {
            System.out.println(Integer.toBinaryString(n));
            if ((n & 1) == 0) {
                n >>>= 1;
            } else if (n == 3 || (((n >>> 1) & 1) == 0)) {
                n--;
            } else {
                n++;
            }
            step++;
        }
        return step;
    }
}
